// pages/month_results_detail/month_results_detail.js
var util = require('../../utils/util');
var App = getApp();
function jsonSort(jsonObj) {
    let arr = [];
    for (var key in jsonObj) {
        arr.push(key)
    }
    arr.sort();
    let str = '';
    for (var i in arr) {
        str += arr[i] + "=" + jsonObj[arr[i]] + "&"
    }
    return str.substr(0, str.length - 1)
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        membership_id: '',
        time: '',
        order_list: [],
        total_price: 0
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var This = this;
        This.setData({
            membership_id: options.id,
            time: options.time
        })

        This.loading();
        var titme_time = This.data.time.slice(5,7) + "月" + This.data.time.slice(8,10) + '日'
        wx.setNavigationBarTitle({
            title: titme_time + "业绩"
        })
    },
    loading() {
        var This = this;
        App._get('coach/member/get_date_info', {
            date_str: This.data.time,
            // openid: 1,
            // store_id: 53,
            // phone: 15612340001,
            phone: wx.getStorageSync('phone'),
            openid: wx.getStorageSync('openid'),
            store_id: wx.getStorageSync('store_id'),
        }, function(res) {
            if (res.status == 1) {
                This.setData({
                    order_list: res.achievement_data,
                    total_price: res.achievement_moeny
                })
            } else {
                wx.showToast({
                    title: res.error,
                    image: '../../image/icon_danger.png',
                    duration: 2000
                })
            }
        })
    },
    details(e) {
        console.log(e)
        var This = this;
        wx.navigateTo({
            url: '/pages/month_results_detail_detail/month_results_detail_detail?id=' + e.currentTarget.id + '&time=' + This.data.time + '&img=' + e.currentTarget.dataset.ids + "&name=" + e.currentTarget.dataset.name,
        })
    },
    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function() {

    }
})